$.extend({
    getUserTimeLine(e) {
        const myChart = echarts.init(e, null);

        function getData() {
            let result = []
            let person =['严威','李康乐','章宇鑫','徐一飞','武润泽','姚奎','俞文祥','汪念','张豆豆']
            result.push(person)
            for (let i = 2011; i <= 2020; i++) {
                let tmp = []
                for (let j = 0;j < person.length; j++) {
                    tmp.push(Math.round(Math.random() * 100));
                }
                result.push(tmp)
            }
            return result
        }

        function getYear(data) {
            let nowYear = new Date().getFullYear();
            let prevYear = nowYear - data.length + 2;
            let result = []
            for (; prevYear <= nowYear ; prevYear++) {
                result.push(prevYear)
            }
            return result;
        }

        function getSeries(data) {
            let result = []
            data.filter((t, index) => index === 0).forEach(t => {
                t.forEach(j => {
                    result.push({
                        name: j,
                        type: 'bar',
                        label: {
                            show: true,
                            formatter: '{a}',
                            position: 'bottom'
                        }
                    })
                })
            })
            result.push({
                name: '总数占比',
                type: 'pie',
                center: ['50%', '20%'],
                radius: '25%'
            })
            return result;
        }

        function getOptions(data, year) {
            let result = []
            let names = data.splice(0, 1)
            for (let row = 0; row < data.length; row++) {
                let tmp = []
                let tmp1 = []
                for (let col = 0; col < data[row].length; col++) {
                    tmp.push({
                        data: [{value: data[row][col]}]
                    })
                    tmp1.push({
                        name: names[0][col],
                        value: data[row][col]
                    })
                }
                tmp.push({data: tmp1})
                result.push({
                    title: {text: year[row] + '年前10用户成果数'},
                    series: tmp
                })
            }
            return result
        }

        const option = {
            baseOption: {
                timeline: {
                    axisType: 'category',
                    playInterval: 2000,
                    currentIndex: 0,
                    data: [],
                    label: {
                        formatter : function(s) {
                            return (new Date(s)).getFullYear();
                        }
                    }
                },
                title: {
                    subtext: '测试数据'
                },
                toolbox: {
                    feature: {
                        saveAsImage: {},
                        restore: {}
                    }
                },
                tooltip: {
                    formatter: '{b0}: {c0}个'
                },
                legend: {
                    type: 'scroll',
                    orient: 'vertical',
                    left: 'right',
                    top: 45,
                    bottom: 20
                },
                calculable : true,
                grid: {
                    top: '40%',
                    bottom: '18%'
                },
                xAxis: [{
                    'type':'category'
                }],
                yAxis: [{
                    type: 'value',
                    name: '数目'
                }],
            }
        };
        myChart.setOption(option)
        myChart.showLoading()

        setTimeout(function () {
            myChart.hideLoading()
            let data = getData()
            let names = data[0]
            let year = getYear(data)
            let series = getSeries(data)
            let options = getOptions(data, year)

            myChart.setOption({
                baseOption: {
                    timeline: {
                        autoPlay: true,
                        currentIndex: 1,
                        data: year
                    },
                    legend: {
                        data: names
                    },
                    series: series
                },
                options: options
            })
        }, 1)

    }
})